﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;

namespace BDH.DAL
{
    using BDH.DAL.Entities;
    public class NhatroDAL : BaseDAL, BDH.UTL.IBaseDAL
    {
        public int Count()
        {
            throw new NotImplementedException();
        }

        public DataTable Select()
        {
            string sql = @" SELECT n.id,ten,chunha,diachi,dienthoai,d.tenduong 
                            FROM Nhatro n JOIN Duong d ON n.duong_id = d.id ";
            return ExecuteQuery(sql);
        }

        public DataTable Select(string id)
        {
            throw new NotImplementedException();
        }

        public DataTable Select(int id)
        {
            string sql = @" SELECT n.id,n.ten,chunha,diachi +' '+ d.tenduong as diachi,dienthoai 
                            FROM Nhatro n JOIN Duong d ON n.duong_id = d.id 
                            WHERE duong_id = '{0}' ";
            sql = string.Format(sql, id);
            return ExecuteQuery(sql);
        }

        public DataTable Select(string id1, string id2)
        {
            throw new NotImplementedException();
        }

        public DataTable Select(object obj)
        {
            throw new NotImplementedException();
        }

        public object GetByKey(object key)
        {
            throw new NotImplementedException();
        }

        public bool Delete(long id)
        {
            string sql = @" DELETE FROM Nhatro WHERE id = {0} ";
            sql = string.Format(sql, id);
            return ExecuteNonQuery(sql) > 0 ? true : false;
        }

        public bool Insert(object obj)
        {
            var o = (Nhatro)obj;
            string sql = @" INSERT INTO Nhatro(ten,chunha,diachi,dienthoai,duong_id) 
                                   VALUES(N'{0}', N'{1}', N'{2}', '{3}', '{4}') ";
            sql = string.Format(sql, o.ten,o.chunha,o.diachi,o.dienthoai,o.duong_id);
            return ExecuteNonQuery(sql) > 0 ? true : false;
        }

        public bool Update(object obj)
        {
            var o = (Nhatro)obj;
            string sql = @" UPDATE Nhatro SET ten = N'{0}', chunha = N'{1}', diachi = N'{2}', dienthoai = '{3}' WHERE id = {4} ";
            sql = string.Format(sql, o.ten,o.chunha,o.diachi,o.dienthoai, o.id);
            return ExecuteNonQuery(sql) > 0 ? true : false;
        }
    }
}
